package com.googlecode.nacl_optimizer.tests;

import java.io.IOException;

import junit.framework.Assert;

import org.junit.Test;

import com.googlecode.nacl_optimizer.elf.StdoutParser;


public class ExtractCOPTests
{
    @Test
    public void extract_cop_1()
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_code_of_operation( "   20007:\t90                   \tnop" )
                , "nop");
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_2() 
    {
        try {
        Assert.assertEquals(
                "and   ",
                StdoutParser.extract_code_of_operation( "   2008f:\t83 e4 f0             \tand    $0xfffffff0,%esp")
                );
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_3() //
    {
        try {
        Assert.assertEquals(
                "lea   ",
                StdoutParser.extract_code_of_operation( "   24359:\t8d bc 27 00 00 00 00 \tlea    0x0(%edi,%eiz,1),%edi"));
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_4()
    {
        try {
        Assert.assertEquals(
                "call  ",
                StdoutParser.extract_code_of_operation( "   34c9b:\te8 40 b5 fe ff       \tcall   201e0 <__do_global_dtors_aux>"));
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_5()
    {
        try {
        Assert.assertEquals(
                "nop",
                StdoutParser.extract_code_of_operation( "   2460a:\tff ff ff "));
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_6()
    {
        try {
        Assert.assertEquals(
                "nop",
                StdoutParser.extract_code_of_operation( "   248ce:\t00 "));
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_7()
    {
        try {
        Assert.assertEquals(
                "hlt   ",
                StdoutParser.extract_code_of_operation( "   34cbf:\tf4                   \thlt    "));
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_cop_8()
    {
        try {
        Assert.assertEquals(
                "movzbl",
                StdoutParser.extract_code_of_operation( "   29d33:\t0f b6 40 01          \tmovzbl 0x1(%eax),%eax"));
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }

}
